﻿using System.Collections.Generic;
namespace KxParser.Lexer.Common
{
    /// <summary>
    /// This class represents a token
    /// </summary>
    public class Token
    {
        /// <summary>
        /// Token name
        /// </summary>
		public string Name { get; set; }

		/// <summary>
		/// Token name
		/// </summary>
		public List<string> AdditionalNames { get; set; }

		public string FullName
		{
			get
			{
				string fullName = Name;
				foreach (string addName in AdditionalNames)
				{
					fullName += Global.TokenNameSeparator + addName;
				}
				return fullName;
			}
		}

        /// <summary>
        /// Token content
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// Is token ignored
        /// </summary>
        public bool IsIgnored { get; set; }


        /// <summary>
        /// Tokens line number
        /// </summary>
        public int LineNumber { get; set; }

        /// <summary>
        /// Tokens start index (in line)
        /// </summary>
        public int StartIndex { get; set; }

        /// <summary>
        /// Tokens end index (in line)
        /// </summary>
        public int EndIndex { get; set; }

        /// <summary>
        /// Tokens total index (position from first line, first character)
        /// </summary>
        public int TotalIndex { get; set; }


		public Token()
		{
			AdditionalNames = new List<string>();
		}

        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <filterpriority>2</filterpriority>
        public override string ToString()
        {
            return string.Format("{0}='{1}',[{2}-{3}][{4}-{5}] {6}", FullName , Content, StartIndex, EndIndex, TotalIndex, TotalIndex + (EndIndex - StartIndex), (IsIgnored) ? "*" : "");
        }
    }
}
